package com.lyf.scm.plan.api.controller;

import com.github.pagehelper.PageInfo;
import com.lyf.scm.common.model.ExcelExportDataDTO;
import com.lyf.scm.common.util.ExcelExportUtil;
import com.lyf.scm.plan.api.dto.EChartsDTO;
import com.lyf.scm.plan.api.dto.SalesPlanDirectlyAccuracyDTO;
import com.lyf.scm.plan.api.dto.SalesPlanDirectlyAccuracyInfoDTO;
import com.lyf.scm.plan.domain.service.SalesPlanDirectlyAccuracyService;
import com.rome.arch.core.clientobject.Response;
import com.rome.arch.util.controller.RomeController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

/**
 * 直营预测计划_销售计划准确率
 *
 * @author wangchlei
 * @date 2020/08/13
 */
@Slf4j
@Api(tags = "直营预测计划_销售计划准确率")
@RequestMapping("/api/v1/salesPlanDirectlyAccuracy")
@RomeController
public class SalesPlanDirectlyAccuracyController {
    @Resource
    private SalesPlanDirectlyAccuracyService salesPlanDirectlyAccuracyService;

    @PostMapping("/listByWeek")
    @ApiOperation(value = "按条件查询直营预测计划_销售计划准确率(周)")
    public Response<PageInfo<SalesPlanDirectlyAccuracyInfoDTO>> listWeekBySelective(@RequestBody SalesPlanDirectlyAccuracyDTO salesPlanDirectlyAccuracyDTO) {
        return Response.builderSuccess(salesPlanDirectlyAccuracyService.listWeekBySelective(salesPlanDirectlyAccuracyDTO));
    }

    @PostMapping("/eChartsData")
    @ApiOperation(value = "图表数据接口")
    public Response<EChartsDTO> eChartsData(@RequestBody SalesPlanDirectlyAccuracyDTO salesPlanDirectlyAccuracyDTO) {
        return Response.builderSuccess(salesPlanDirectlyAccuracyService.eChartsData(salesPlanDirectlyAccuracyDTO));
    }
    @PostMapping("/export")
    @ApiOperation(value = "导出")
    public void export(@RequestBody SalesPlanDirectlyAccuracyDTO salesPlanDirectlyAccuracyDTO, @RequestParam Integer type, HttpServletResponse httpServletResponse) {
        try {
            ExcelExportDataDTO excelExportDataDTO = salesPlanDirectlyAccuracyService.export(salesPlanDirectlyAccuracyDTO, type);
            ExcelExportUtil.exportExcel(httpServletResponse, excelExportDataDTO);
        } catch (Exception e) {
            ExcelExportUtil.handleExceptionResponse(httpServletResponse, e);
        }
    }

    @PostMapping("/delete")
    @ApiOperation(value = "删除对应标识数据")
    public Response delete(@RequestParam("opSign") String opSign) {
        salesPlanDirectlyAccuracyService.delete(opSign);
        return Response.builderSuccess(null);
    }
}
